package com.xinguan.system.controller;


import com.xinguan.handler.BusinessException;
import com.xinguan.responce.Result;
import com.xinguan.responce.ResultCode;
import com.xinguan.system.entity.Department;
import com.xinguan.system.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zzq
 * @since 2021-03-02
 */
@Api(value = "部门人员")
@RestController
@RequestMapping("/department")
public class DepartmentController {
   @Autowired
   private DepartmentService departmentService;
   @RequestMapping("/findDepAndCount")
   @ApiOperation(value="部门查询与总数",notes = "查询部门信息")
   public Result findDeptAndCount(){
      List<Department> departments=departmentService.findDeptAndCount();
      if (departments.size()==0){
           throw new BusinessException(ResultCode.DEPT_NOT_FOUND_EXCEPTION.getCode(),ResultCode.DEPT_NOT_FOUND_EXCEPTION.getMessage());
      }
      return Result.ok().data("departments",departments);
   }
}

